package com.sk.bilibili.model.fragment.channel;

import com.sk.api.annotations.Autowired;
import com.sk.bilibili.callBack.RequestCallBack;
import com.sk.bilibili.mapper.FollowThemMapper;
import com.sk.bilibili.mapper.ThemBannerMapper;
import com.sk.bilibili.mapper.ThemMapper;
import com.sk.bilibili.model.BaseRefreshModel;
import com.sk.bilibili.other.JsonMap;
import com.sk.bilibili.utils.RequestUtils;
import com.sk.bilibili.view.fragment.channel.ThemFragment;

public class ThemModel extends BaseRefreshModel<ThemFragment> {

    @Autowired
    ThemBannerMapper themBannerMapper;
    @Autowired
    ThemMapper themMapper;
    @Autowired
    FollowThemMapper followThemMapper;
    private int size=6;

    public void refresh(Integer typeId) {
        RequestUtils.process(themBannerMapper.getThemBanner(typeId),
                themBanners -> view.loadBannerSuccess(themBanners));
        refreshThem(typeId);
        refreshSerial(typeId);
        refreshFinish(typeId);
    }

    public void refreshFinish(Integer typeId) {
        RequestUtils.process(themMapper.getRandom(true, size, typeId),
                thems -> view.loadFinishSuccess(thems));
    }

    public void refreshSerial(Integer typeId) {
        RequestUtils.process(themMapper.getRandom(false, size, typeId),
                thems -> view.loadSerialSuccess(thems));
    }

    public void refreshThem(Integer typeId) {
        RequestUtils.process(themMapper.getRandom(null, size, typeId),
                thems -> view.loadRecommendSuccess(thems));
    }

    public void followThem(Integer id) {
        JsonMap map = new JsonMap();
        map.put("themId",id);
        RequestUtils.process(followThemMapper.add(map), unused -> view.followThemSuccess());
    }

}